package com.neu.elm.controller;

import com.neu.elm.po.DeliveryAddress;
import com.neu.elm.service.DeliveryAddressService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:csw
 * @Date: 9:16 2020/9/16
 */
@RestController
@RequestMapping("/deliveryAddressController")
public class DeliveryAddressController {
    @Resource
    private DeliveryAddressService deliveryAddressService;

    //http://localhost:8088/elm/deliveryAddressController/listDeliveryAddressByUserId?userId=12345671111
    @RequestMapping("/listDeliveryAddressByUserId")
    public List<DeliveryAddress> listDeliveryAddressByUserId(DeliveryAddress deliveryAddress) throws Exception{
        return deliveryAddressService.listDeliveryAddressByUserId(deliveryAddress.getUserId());
    }

    //http://localhost:8088/elm/deliveryAddressController/getDeliveryAddressById?daId=1
    @RequestMapping("/getDeliveryAddressById")
    public DeliveryAddress getDeliveryAddressById(DeliveryAddress deliveryAddress) throws Exception{
        return deliveryAddressService.getDeliveryAddressById(deliveryAddress.getDaId());
    }

    //http://localhost:8088/elm/deliveryAddressController/saveDeliveryAddress?contactName=陈胜旺&contactSex=1&contactTel=123456&address=大滨海&userId=123
    @RequestMapping("/saveDeliveryAddress")
    public int saveDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception{
        return deliveryAddressService.saveDeliveryAddress(deliveryAddress);
    }

    //http://localhost:8088/elm/deliveryAddressController/updateDeliveryAddress?contactName=csw&contactSex=1&=&contactTel=1234313213212&address=南京&daId=2
    @RequestMapping("/updateDeliveryAddress")
    public int updateDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception{
        return deliveryAddressService.updateDeliveryAddress(deliveryAddress);
    }

    //removeDeliveryAddress
    @RequestMapping("/removeDeliveryAddress")
    public int removeDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception{
        return deliveryAddressService.removeDeliveryAddress(deliveryAddress.getDaId());
    }
}
